home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 66
/
Vol 66.iso
/
games
/
bob_espo.swf
/
scripts
/
__Packages
/
RoamingJellyFish.as
< prev
next >
Wrap
Text File
|
2013-04-24
|
7KB
|
254 lines
class RoamingJellyFish extends MovingObject
{
static var sLINKAGE_NAME = "mcJellyFish";
static var nCOUNTER = 0;
static var sSTATE_STOPROAM = "StopRoam";
static var nSPEED = 1;
static var nMAX_WAIT_TIME = 75;
static var nMIN_DEPTH = 300000;
static var nDEPTH_FACTOR = 25;
function RoamingJellyFish(_nX, _nY)
{
super(CTRLGame.getRef().mcRef.attachMovie(RoamingJellyFish.sLINKAGE_NAME,RoamingJellyFish.sLINKAGE_NAME + RoamingJellyFish.nCOUNTER,CTRLGame.nMIN_DEPTH));
this.nId = RoamingJellyFish.nCOUNTER++;
this.mcRef._x = _nX;
this.mcRef._y = _nY;
this.adaptDepth();
var _loc5_ = Math.round(Math.random() * 66) + 1;
this.mcRef.mcState.jelly.jelly.gotoAndPlay(_loc5_);
this.nWaitTime = 0;
if(Controller.getRef().isPaused())
{
this.doPause();
}
}
function stopRoaming()
{
this.setState(RoamingJellyFish.sSTATE_STOPROAM);
}
function calculateDepth(_nY, _nAdd)
{
var _loc4_ = Math.round(_nY) * RoamingJellyFish.nDEPTH_FACTOR + RoamingJellyFish.nMIN_DEPTH + _nAdd;
return _loc4_;
}
function cleanUp()
{
super.cleanUp();
this.mcRef.swapDepths(7777);
this.mcRef.removeMovieClip();
}
function doPause()
{
super.doPause();
this.mcRef.mcState.jelly.jelly.stop();
this.mcRef.mcState.shadow.stop();
}
function doUnPause()
{
if(!CTRLGame.getRef().Screen.isInMiniGame())
{
super.doUnPause();
this.mcRef.mcState.jelly.jelly.play();
this.mcRef.mcState.shadow.play();
}
}
function resumeAnim()
{
super.doUnPause();
this.mcRef.mcState.jelly.jelly.play();
this.mcRef.mcState.shadow.play();
}
function adaptDepth()
{
this.mcRef.swapDepths(this.calculateDepth(this.mcRef._y,CTRLGame.nJELLYFISH_ADD + this.nId));
}
function manageMovement()
{
if(this.canMove() && this.nMovement == 0)
{
if(this.sState == MovingObject.sSTATE_DOWN || (this.sState == MovingObject.sSTATE_UP || (this.sState == MovingObject.sSTATE_LEFT || this.sState == MovingObject.sSTATE_RIGHT)))
{
this.setIdleState();
}
else if(this.isNextMoveGood(this.nCurrentDir))
{
switch(this.nCurrentDir)
{
case CTRLGame.nDIR_UP:
this.setState(MovingObject.sSTATE_UP);
break;
case CTRLGame.nDIR_DOWN:
this.setState(MovingObject.sSTATE_DOWN);
break;
case CTRLGame.nDIR_LEFT:
this.setState(MovingObject.sSTATE_LEFT);
break;
case CTRLGame.nDIR_RIGHT:
this.setState(MovingObject.sSTATE_RIGHT);
}
this.nMovement = MovingObject.nMAX_MOVEMENT;
}
else
{
do
{
var _loc2_ = Math.round(Math.random() * 3);
}
while(_loc2_ == this.nCurrentDir);
if(this.isNextMoveGood(_loc2_))
{
if(_loc2_ == CTRLGame.nDIR_UP)
{
this.setState(MovingObject.sSTATE_UP);
}
else if(_loc2_ == CTRLGame.nDIR_DOWN)
{
this.setState(MovingObject.sSTATE_DOWN);
}
else if(_loc2_ == CTRLGame.nDIR_LEFT)
{
this.setState(MovingObject.sSTATE_LEFT);
}
else
{
this.setState(MovingObject.sSTATE_RIGHT);
}
this.nCurrentDir = _loc2_;
this.nMovement = MovingObject.nMAX_MOVEMENT;
}
else
{
this.setIdleState();
}
}
}
}
function setIdleState()
{
this.nWaitTime = RoamingJellyFish.nMAX_WAIT_TIME;
switch(this.nCurrentDir)
{
case CTRLGame.nDIR_UP:
this.setState(MovingObject.sSTATE_IDLE_UP);
break;
case CTRLGame.nDIR_DOWN:
this.setState(MovingObject.sSTATE_IDLE_DOWN);
break;
case CTRLGame.nDIR_LEFT:
this.setState(MovingObject.sSTATE_IDLE_LEFT);
break;
case CTRLGame.nDIR_RIGHT:
this.setState(MovingObject.sSTATE_IDLE_RIGHT);
}
}
function isNextMoveGood(_nNextDir)
{
var _loc3_ = this.getWishPos(_nNextDir);
var _loc4_ = this.getWishMidPos(_nNextDir);
var _loc5_ = false;
if(this.isTrackOkay(_nNextDir) && (!CTRLGame.getRef().isTouchingWall(_loc4_.x,_loc4_.y) && (!CTRLGame.getRef().isJellyTouchingDirtWall(_loc3_.x,_loc3_.y) && (!CTRLGame.getRef().isJellyTouchingAlguae(_loc3_.x,_loc3_.y) && !CTRLGame.getRef().isJellyTouchingJelly(_loc3_.x,_loc3_.y,this)))))
{
_loc5_ = true;
}
return _loc5_;
}
function IdleUp()
{
if(this.canMove())
{
if(this.nWaitTime > 0)
{
this.nWaitTime = this.nWaitTime - 1;
}
if(this.nWaitTime <= 0)
{
this.manageMovement();
}
}
}
function IdleDown()
{
if(this.canMove())
{
if(this.nWaitTime > 0)
{
this.nWaitTime = this.nWaitTime - 1;
}
if(this.nWaitTime <= 0)
{
this.manageMovement();
}
}
}
function IdleLeft()
{
if(this.canMove())
{
if(this.nWaitTime > 0)
{
this.nWaitTime = this.nWaitTime - 1;
}
if(this.nWaitTime <= 0)
{
this.manageMovement();
}
}
}
function IdleRight()
{
if(this.canMove())
{
if(this.nWaitTime > 0)
{
this.nWaitTime = this.nWaitTime - 1;
}
if(this.nWaitTime <= 0)
{
this.manageMovement();
}
}
}
function Left()
{
if(this.nMovement > 0 && this.canMove())
{
this.mcRef._x -= RoamingJellyFish.nSPEED;
this.nMovement -= RoamingJellyFish.nSPEED;
}
this.manageMovement();
}
function Up()
{
if(this.nMovement > 0 && this.canMove())
{
this.mcRef._y -= RoamingJellyFish.nSPEED;
this.nMovement -= RoamingJellyFish.nSPEED;
this.adaptDepth();
}
this.manageMovement();
}
function Right()
{
if(this.nMovement > 0 && this.canMove())
{
this.mcRef._x += RoamingJellyFish.nSPEED;
this.nMovement -= RoamingJellyFish.nSPEED;
}
this.manageMovement();
}
function Down()
{
if(this.nMovement > 0 && this.canMove())
{
this.mcRef._y += RoamingJellyFish.nSPEED;
this.nMovement -= RoamingJellyFish.nSPEED;
this.adaptDepth();
}
this.manageMovement();
}
function StopRoam()
{
}
}